<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>管理员列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form id="frm1" class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">员工号</label>
                            <div class="layui-input-inline">
                                <input type="text" name="eno" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">员工名</label>
                            <div class="layui-input-inline">
                                <input type="text" name="name" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-label">月份选择</div>
                        <div class="layui-input-inline" style="width: 200px;">
                            <select name="month" class="province-selector" data-value="试用会员" lay-filter="province-1">
                                <option value="">--选择月份--</option>
                                <option value="1">1月</option>
                                <option value="2">2月</option>
                                <option value="3">3月</option>
                                <option value="4">4月</option>
                                <option value="5">5月</option>
                                <option value="6">6月</option>
                                <option value="7">7月</option>
                                <option value="8">8月</option>
                                <option value="9">9月</option>
                                <option value="10">10月</option>
                                <option value="11">11月</option>
                                <option value="12">12月</option>
                            </select>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>
        <fieldset class="table-search-fieldset">
            <legend>批量新增</legend>
            <div class="layui-btn-container">
                <button type="button" class="layui-btn" id="test3"><i class="layui-icon"></i>上传文件</button>
            </div>
        </fieldset>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 添加 </button>
                <button class="layui-btn layui-btn-normal layui-btn-sm data-download-btn" lay-event="exports"> 导出 </button>
            </div>
        </script>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
        </script>

    </div>
</div>
<script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'table','upload'], function () {
        var $ = layui.jquery,
            form = layui.form,
            upload = layui.upload;
            table = layui.table;

        var tableIns = table.render({

            elem: '#currentTableId',
            url: '/salary/salaryPage',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],

            cols: [[
                {field: 'empno',  title: '员工号', sort: true,width: 100},
                {field: 'ename',  title: '员工名',width: 80},
                {field: 'month', title: '工资月份'},
                {field: 'basicsalary',title: '基本工资'},
                {field: 'reward',title: '月度奖金'},
                {field: 'taxes',title: '个税扣款'},
                {field: 'insurance',title: '五险一金'},
                {field: 'total',title: '总工资',templet: function(d){
                        return d.basicsalary+d.reward-d.taxes-d.insurance;
                    }},
                {field: 'ctime',title: '创建时间'},
                {title: '操作', toolbar: '#currentTableBar', align: "right"}
            ]],
            limits: [5 , 10, 15, 20, 25, 50, 100],
            limit: 5,
            page: true,
            skin: 'line',
            done: function(res, curr, count){
                $("[data-field='id']").css('display','none');
            }
        });
        var data;
        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            data = data.field;
            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: data
            });
            return false;
        });

        /**
         * toolbar监听事件
         */
        var tableIns = table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {  // 监听添加操作
                var index = layer.open({
                    title: '添加工资信息',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: './workerlist.html',
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            }else if(obj.event==='exports'){
                location.href="/salary/download?"+$("#frm1").serialize();
            }
        });

        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
            console.log(obj)
        });
        //文件上传解析
        upload.render({
            elem: '#test3'
            ,url: '/salary/batchadd' //此处配置你自己的上传接口即可
            ,accept: 'file' //普通文件
            ,done: function(res){
                layer.msg('上传成功');
                console.log(res);
            }
        });
        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {
                var s=JSON.stringify(data);
                localStorage.setItem("ucurruser",s);
                var index = layer.open({
                    title: '编辑工资',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: './salarymanagementedit.html',
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            } else if (obj.event === 'delete') {
                layer.confirm('真的删除行么', function (index) {
                    $.post("/salary/delete","id="+data.id,function(res){
                        if(res.code==200){
                            layer.msg('删除成功');
                            obj.del();
                        }else{
                            layer.msg('删除失败：'+res.msg);
                        }
                        layer.close(index);
                    })

                });
            }
        });

    });
</script>

</body>
</html>